// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "MotionAnimInfos.generated.h"

/**
 * 
 */

UENUM(BlueprintType)
enum class EAnimType:uint8
{
	Unknown,
	Scale,
	Translate,
	Fade,
	Dissolve,
	Marquee
};

UENUM(BlueprintType)
enum class EDispatchMode:uint8
{
	WholeLayer,
	ContentElement
};

UENUM(BlueprintType)
enum class EAnimDirection:uint8
{
	Up,
	Down,
	Left,
	Right
};

UENUM(BlueprintType)
enum class ELayerMask:uint8
{
	Layer0,
	Layer1,
	Layer2,
	Layer3,
	Layer4,
	Layer5,
	Layer6,
	Layer7,
	Layer8,
	Layer9,
};

UENUM(BlueprintType)
enum class EAnimTarget:uint8
{
	WholeLayer,
	ContentElement
};


USTRUCT(BlueprintType)
struct FMotionAnimInfo
{
	GENERATED_USTRUCT_BODY()


	FMotionAnimInfo(): TargetLayer(), Type(), Direction(EAnimDirection::Up),
	                   DispatchMode(EDispatchMode::WholeLayer),
	                   StartOffset(0), Duration(0)
	{
	}

	UPROPERTY(EditAnywhere)
	ELayerMask TargetLayer;

	UPROPERTY(EditAnywhere)
	EAnimType Type;

	UPROPERTY(EditAnywhere, meta=(EditCondition ="Type==EAnimType::Translate||Type==EAnimType::Marquee", EditConditionHides))
	EAnimDirection Direction;

	UPROPERTY(EditAnywhere)
	EDispatchMode DispatchMode;

	UPROPERTY(EditAnywhere, meta=(EditCondition ="Duration>0", EditConditionHides))
	TObjectPtr<UCurveFloat> Curve;

	// 当DispatchMode为ContentElement时才生效
	UPROPERTY(EditAnywhere, meta=(EditCondition ="DispatchMode==EDispatchMode::ContentElement", EditConditionHides))
	float StartOffset;

	UPROPERTY(EditAnywhere)
	float Duration;
};

USTRUCT(BlueprintType)
struct FAnimActionInfo
{
	GENERATED_USTRUCT_BODY()


	FAnimActionInfo():  Type(), Direction(), AnimTarget(),
	                   ElementId(-1), StartOffset(0), Duration(0)
	{
	}

    static FAnimActionInfo From(const FMotionAnimInfo& AnimInfo)
	{
		FAnimActionInfo ActionInfo;
		ActionInfo.Layer=nullptr;
		ActionInfo.Type = AnimInfo.Type;
		ActionInfo.Direction = AnimInfo.Direction;
		ActionInfo.AnimTarget = AnimInfo.DispatchMode == EDispatchMode::WholeLayer
			             ? EAnimTarget::WholeLayer
			             : EAnimTarget::ContentElement;
		ActionInfo.Curve = AnimInfo.Curve;
		ActionInfo.ElementId = -1;
		ActionInfo.StartOffset = AnimInfo.StartOffset;
		ActionInfo.Duration = AnimInfo.Duration;
		return ActionInfo;
	}

	TWeakObjectPtr<USceneComponent> Layer;
	
	EAnimType Type;
	
	EAnimDirection Direction;
	
	EAnimTarget AnimTarget;
	
	TWeakObjectPtr<UCurveFloat> Curve;
	
	int32 ElementId;
	
	float StartOffset;
	
	float Duration;
};
